﻿//Dùng tại frmTongHopTT

using System;
using System.Data.SqlClient;
using System.Data;
using System.Globalization;

using DevExpress.XtraReports.UI;
using prjKQXS_DLL;

namespace prjKQXS_Report.Truyen_thong
{
    public partial class rptThongKeTT_DV : DevExpress.XtraReports.UI.XtraReport
    {
        public DataTable dtSource;
        public string TyLe = "";
        public string VietBangSo = "";

        public rptThongKeTT_DV()
        {
            InitializeComponent();
        }

        private void rptThongKeTT_CB_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            xrlblNgay.Text = "Từ ngày " + ((DateTime)pTuNgay.Value).ToString("dd/MM/yyyy") + " đến ngày " + ((DateTime)pDenNgay.Value).ToString("dd/MM/yyyy");

            SqlConnection conn = new SqlConnection(BienTc.connString);
            conn.Open();
            //string sql = "SELECT Top 1 GiaVe FROM vVESO WHERE NgayMoThuong = @Ngay and GiaVe is not NULL and isPublic = 1";
            string sql = "SELECT Top 1 GiaVe FROM vVESO WHERE NgayMoThuong between  @TuNgay and @DenNgay";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@TuNgay", pTuNgay.Value);
            cmd.Parameters.AddWithValue("@DenNgay", pDenNgay.Value );//20.02.2014

            try
            {
                xrlblGiaVe.Text = "Giá vé: " + ((int)cmd.ExecuteScalar()).ToString("#,#đ");
            }
            catch (NullReferenceException ex)
            {
                xrlblGiaVe.Text = "Giá vé: ";
            }            

            lblHT.Text = TyLe;
            lblBangso.Text = VietBangSo;

            Report_DAL report_dal = new Report_DAL();
            dsReports dsReports1 = new dsReports();
            dsReports1 = report_dal.reportDungChung(dsReports1);

//            sql = @"SELECT Pchutich AS Phochutich
//                                ,Congty
//                                ,Sotuphap
//                                ,Sotaichinh
//                                ,Congantinh
//                                ,MattranTQ
//                                ,ThanhtraNN
//                                ,Thuky
//                            from KETQUATT 
//                            where NgayMoThuong = @Ngay";
            sql = @"SELECT top 1 Pchutich AS Phochutich
                                ,Congty
                                ,Sotuphap
                                ,Sotaichinh
                                ,Congantinh
                                ,MattranTQ
                                ,ThanhtraNN
                                ,Thuky
                            from KETQUATT 
                            where 
                            NgayMoThuong between  @TuNgay and @DenNgay";//20.02.2014
            SqlDataAdapter da1 = new SqlDataAdapter(sql, conn);
            da1.SelectCommand.Parameters.AddWithValue("@TuNgay", pTuNgay.Value);
            da1.SelectCommand.Parameters.AddWithValue("@DenNgay", pDenNgay.Value);
            da1.Fill(dsReports1.Tables["Hoidongtt"]);

            dsReports1.Tables.Remove("TruyenThong");
            dsReports1.Tables.Add(dtSource);
            this.DataSource = dsReports1;
            this.DataMember = "TruyenThong";
        }

        int stt = 0;
        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            xrtcSTT.Text = (++stt).ToString();
        }

        //private void lblHT1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        //{
        //    {
        //        xrtcSTT.Text = (++stt).ToString();
        //    }

        //}
    }
}
